/**
 * 
 */
package hoan.nguyen.advice;

import java.lang.reflect.Method;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

/**
 * @author Horizon
 * 
 */
@Aspect
public class LoggingAdvice  {

	/** Time in milliseconds */
	long startTime = 0;

	/** Time in milliseconds */
	long finishTime = 0;

	@Before(value = "target")
	public void before(Method method, Object[] args, Object target) throws Throwable {
		startTime = System.currentTimeMillis();
		System.out.println("Executing method " + method.getName() + " on object "
				+ target.getClass().getName());
	}

	@AfterReturning
	public void afterReturning(Object returnValue, Method method, Object[] args, Object target)
			throws Throwable {
		finishTime = System.currentTimeMillis();
		double totalDuration = finishTime - startTime;
		System.out.println("Finished executing method " + method.getName() + " on object "
				+ target.getClass().getName() + " in " + totalDuration / 1000 + " seconds.");
	}

}
